package com.jxd.project.report.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jxd.project.report.model.Project;
import com.jxd.project.report.service.IProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName ProjectController
 * @Description TODO
 * @Author 孙福桐
 * @Date 2025/10/1 18:29
 * @Version 1.0
 */
@RestController
public class ProjectController {
    @Autowired
    private IProjectService projectService;

    /**
     * 修改项目
     * @param project
     * @return
     */
    @RequestMapping("/editProject")
    public String editProject(@RequestBody Project project){
        if (projectService.updateById(project)) return "success";
        else return "fail";
    }

    /**
     * 新增项目
     * @param project
     * @return
     */
    @RequestMapping("/addProject")
    public String addProject(@RequestBody Project project){
        if (projectService.addProject(project)) return "success";
        else return "fail";
    }

    /**
     * 获取项目
     * @param paramMap
     * @return
     */
    @RequestMapping("/getProject")
    public Map<String,Object> getProject(@RequestBody Map<String,String> paramMap){
        return projectService.getProject(paramMap);
    }

    /**
     * 获取项目列表
     * @param deptno
     * @return
     */
    @RequestMapping("/getProjectList")
    public List<Project> getProjectList(int deptno){
        QueryWrapper<Project> qw = new QueryWrapper<>();
        qw.and(i -> i.eq("deptno",deptno).eq("isdelete",0));
        List<Project> projectList = projectService.list(qw);
        return projectList;
    }

    /**
     * 删除项目
     * @param pids
     * @return
     */
    @RequestMapping("/deleteProject")
    public String deleteProject(@RequestBody List<Integer> pids){
        if (projectService.removeProject(pids)) return "success";
        else return "fail";
    }
}
